package com.deyuanyun.pic.pipe.service.impl;

import com.caixu.beanvalidateutil.imlclass.BeanValidateUtil;
import com.caixu.beanvalidateutil.imlclass.VResult;
import com.caixu.beanvalidateutil.utils.ObjectUtil;
import com.deyuanyun.pic.common.util.MapUtil;
import com.deyuanyun.pic.pipe.domain.exceldomain.PipeLineCentreImportDemo;
import com.deyuanyun.pic.pipe.mapper.DyyPipeLineMapper;
import com.deyuanyun.pic.pipe.service.PipeLineService;
import com.github.pagehelper.Page;











import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service("lineService")
public class PipeLineServiceImpl implements PipeLineService {

	private static Logger log = LogManager.getLogger(PipeLineServiceImpl.class);

	@Resource
	private DyyPipeLineMapper dyyPipeLineMapper;

	

	@Override
	public int delGis(Map data) {
		// TODO Auto-generated method stub
		return dyyPipeLineMapper.delGis(data);
	}

	@Override
	public Page<HashMap<String, Object>> findPage(HashMap map) {
		// TODO Auto-generated method stub
		return dyyPipeLineMapper.findPage(map);
	}

	@Override
	public boolean importData(List<PipeLineCentreImportDemo> data)
			throws IOException, Exception {

		VResult b = BeanValidateUtil.vali2(data);
		List<Map> insertData = new ArrayList<Map>();
		Map<String, Object> bean = null;
		if (b.isRelult()) {
			for (PipeLineCentreImportDemo info : data) {
				if(ObjectUtil.isNotNullEmpty(info.getRecordtime()))
				{
					info.setRecordtime(null);
				}
				bean = MapUtil.beanToMap(info);
				bean.put("id", UUID.randomUUID().toString().replaceAll("-", ""));
				bean.put("createDate", null);
				bean.put("createUser", null);
				bean.put("createRemark", null);
				System.out.println("====> ok:"+dyyPipeLineMapper.insertPosit(bean));
			}
		}

		return true;
	}
}
